Skip to content

10 scraping reliability improvements for source ingestion pipeline - #81

Open
potemkin666 with Copilot wants to merge 3 commits into
mainfrom
copilot/improve-brialert-scraping-sources
Open

10 scraping reliability improvements for source ingestion pipeline#81
potemkin666 with Copilot wants to merge 3 commits into
mainfrom
copilot/improve-brialert-scraping-sources

Conversation

Copilot AI commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Brialert's source scraping pipeline has multiple failure modes — bot detection, brittle HTML selectors, stale URLs, timeout budget exhaustion, and long quarantine windows — that cause sources to silently drop out of rotation. This PR addresses all 10 identified failure categories across the fetch, parse, schedule, and recovery layers.

Fetch resilience

  • Expanded Playwright allowlist from 2→9 CT/police sources, budget raised 2→6 attempts/run, now also triggers on parser-failure (not just bot-block)
  • Diversified UA pool from 4→12 agents (Chrome/Firefox/Safari/Edge current versions); retries use a randomized browser UA instead of repeating the deterministic one
  • Proxy support via BRIALERT_PROXY_URL / BRIALERT_PROXY_LIST env vars, applied to both fetch() and Playwright browser contexts
  • Adaptive timeouts: fast feeds get 8s (down from 12s), high-value sources get 4 retries (up from 3), freeing budget for slow HTML sources

Fallback & recovery

  • Replacement endpoint fallback: on 404/410/blocked, tries replacementEndpoint / fallbackEndpoint / canonicalEndpoint before quarantining
  • RSS feed auto-discovery: when HTML parsing yields zero items, probes common feed paths (/feed, /rss, /atom.xml, etc.) and <link rel="alternate"> on the same domain
  • URL path alternatives for 404s: tries www prefix/removal and common path reorganizations (/news//press-releases/)
  • Auto-clear quarantine on success: successful runs now reset the quarantined flag, fixing the bug where recovered sources stayed quarantined indefinitely

Parsing

  • Multi-strategy HTML parsing — 4 cascading strategies when CSS selectors yield nothing:
    1. LD+JSON NewsArticle schema extraction
    2. OpenGraph meta (og:title, og:url, article:published_time)
    3. Heuristic link scoring (proximity to <time>, heading tags, article containers; penalizes nav/footer)

Scheduling

  • Least-recently-successful-first ordering prevents source starvation
  • Higher RSS concurrency (6 vs 4) since machine-readable feeds are lightweight
  • Shorter quarantine recheck: 3 days default, 2 days for high-priority lanes (incidents/border/trusted), down from 7 days

New sources

  • 5 Google News RSS aggregator feeds (terrorism UK, counter-terrorism, terror attack, extremism, security threat) as context-lane safety net with requiresKeywordMatch: true

Key config additions

BRIALERT_PROXY_URL / BRIALERT_PROXY_LIST     — proxy rotation
BRIALERT_HIGH_VALUE_MAX_RETRIES              — default 4
BRIALERT_FAST_FEED_TIMEOUT_MS                — default 8000
BRIALERT_FEED_SOURCE_CONCURRENCY_RSS         — default 6
BRIALERT_AUTO_QUARANTINE_RECHECK_HOURS       — default 72 (was 168)
BRIALERT_AUTO_QUARANTINE_RECHECK_HOURS_HIGH_PRIORITY — default 48
BRIALERT_PLAYWRIGHT_PAGE_SETTLE_MS           — default 1500

All 83 existing tests pass; lint clean.

Copilot AI and others added 3 commits April 12, 2026 09:21
1. Expand Playwright browser fallback allowlist (7 more CT/police sources, budget 2→6)
2. Add RSS/Atom feed discovery as fallback for failing HTML sources
3. Add replacement endpoint / mirror fallback logic on 404/410/blocked
4. Diversify user-agents (4→12, Firefox/Safari/Edge, randomised retries)
5. Add proxy/IP rotation support (BRIALERT_PROXY_URL, BRIALERT_PROXY_LIST)
6. Implement adaptive timeout and retry tuning per source
7. Add Google News aggregator RSS feeds as redundant context sources
8. Improve HTML selector resilience with LD+JSON, OG meta, heuristic fallback
9. Implement smarter scheduling (least-recently-successful-first, higher RSS concurrency)
10. Add source health auto-recovery (shorter quarantine recheck, redirect persistence, URL discovery)

Agent-Logs-Url: https://github.com/potemkin666/Brialert/sessions/a6d74a6e-c94a-433a-99ec-d50bd2605258

Co-authored-by: potemkin666 <183807833+potemkin666@users.noreply.github.com>
… feed link matching, valid region for aggregator sources

Agent-Logs-Url: https://github.com/potemkin666/Brialert/sessions/a6d74a6e-c94a-433a-99ec-d50bd2605258

Co-authored-by: potemkin666 <183807833+potemkin666@users.noreply.github.com>
@potemkin666

Copy link
Copy Markdown
Owner

@copilot This branch has conflicts that must be resolved

Use the command line to resolve conflicts before continuing.

data/brialert.sqlite   approve the new changes 

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 610968f6a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 474 to +478
const response = await fetch(url, {
headers: {
...mergedHeaders(source),
...conditionalHeaders
...conditionalHeaders,
...retryHeaders

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Apply configured proxy to standard fetch path

BRIALERT_PROXY_URL/BRIALERT_PROXY_LIST are wired into config.mjs, but fetchText still performs plain fetch() calls without any proxy dispatcher/agent, so the proxy settings have no effect for the primary ingestion path (only Playwright uses them). In environments that require egress via proxy, most sources will continue to fail even though proxy env vars are set.

Useful? React with 👍 / 👎.

Comment thread scripts/build-live-feed.mjs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants